home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 028a / arc_chk.zip / ARC_CHK.C next >
Text File  |  1992-01-06  |  2KB  |  53 lines

  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include <fcntl.h>
  4.  
  5. #define CR "\n"
  6.  
  7. void show_instructions(){
  8.     char *str=CR
  9.     "ARC_CHK Ver 1.0, Checks binary file for identifier string.  If found the"CR
  10.     "program returns an errorlevel 1, otherwise it returns errorlevel 0. "CR
  11.     "Program execution errors return a level 255"CR CR
  12.  
  13.     "Usage: ARC_CHK filename offset string [show_buffer]"CR CR
  14.     "               filename ................ File to check"CR
  15.     "                        offset ......... Start search at this offset"CR
  16.     "                               string .. String to search for"CR CR
  17.     "NOTE: If you add another parameter (anything) the data at the specified"CR
  18.     "      offset will be displayed to you.  This was designed to aid you in"CR
  19.     "      locating a string of text in a file."CR CR;
  20.     printf("%s",str);
  21.     exit(-1);
  22. }
  23.  
  24. main(int argc, char **argv){
  25.     int handle;
  26.     long val;
  27.     char buffer[80];
  28.     if(argc<4) show_instructions();
  29.     argv++;
  30.     if((handle=open(*argv,O_BINARY|O_RDONLY))==-1){
  31.         printf("\n\aError encountered opening %s\n",*argv);
  32.         perror("Error");
  33.         exit(-1);
  34.     }
  35.     argv++;
  36.     val=atol(*argv);
  37.     if((lseek(handle,val,SEEK_SET))==-1){
  38.         printf("\n\aError encountered seeking position in %s\n",*argv);
  39.         perror("Error");
  40.         exit(-1);
  41.     }
  42.     argv++;
  43.     if((read(handle,buffer,strlen(*argv)))==-1){
  44.         printf("\n\aError encountered reading in data\n");
  45.         perror("Error");
  46.         exit(-1);
  47.     }
  48.     if(argc>4) printf("\nData found at specified offset was: %s",buffer);
  49.     close(handle);
  50.     if((strncmp(*argv,buffer,strlen(*argv)))==0) exit(1);
  51.     exit(0);
  52. }
  53.